# -*- coding:utf-8 -*-
import abc


class Tick(object):

    """
    tick数据结构
    """

    __metaclass__ = abc.ABCMeta

    @abc.abstractmethod
    def get_ask(self, adjusted=False):
        """返回ask价格"""
        raise NotImplementedError()

    @abc.abstractmethod
    def get_bid(self):
        """返回bid价格"""
        raise NotImplementedError()

    @abc.abstractmethod
    def get_ask_volume(self):
        """返回ask成交量"""
        raise NotImplementedError()

    @abc.abstractmethod
    def get_bid_volume(self):
        """返回bid成交量"""
        raise NotImplementedError()

    @abc.abstractmethod
    def get_date_time(self):
        "返回时间"
        raise NotImplementedError()

    def get_extra_columns(self):
        return {}


class BasicTick(Tick):
    # Optimization to reduce memory footprint.
    __slots__ = (
        '__date_time',
        '__bid',
        '__ask',
        '__bid_volume',
        '__ask_volume',
        '__extra',
    )

    def __init__(self, date_time, bid, ask, bid_volume, ask_volume, extra={}):
        if bid < ask:
            raise Exception("bid < ask on %s" % (date_time))

        self.__date_time = date_time
        self.__bid = bid
        self.__ask = ask
        self.__bid_volume = bid_volume
        self.__ask_volume = ask_volume
        self.__extra = extra

    def __setstate__(self, state):
        (self.__date_time,
            self.__bid,
            self.__ask,
            self.__bid_volume,
            self.__ask_volume,
            self.__extra) = state

    def __getstate__(self):
        return (
            self.__bid,
            self.__ask,
            self.__bid_volume,
            self.__ask_volume,
            self.__extra
        )

    def get_date_time(self):
        """返回时间"""
        return self.__date_time

    def get_ask(self):
        """返回买一价"""
        return self.__ask

    def get_bid(self):
        """返回卖一价"""
        return self.__bid

    def get_ask_volume(self):
        """返回买一申请的股数,单位(股)"""
        return self.__ask_volume

    def get_bid_volume(self):
        """返回卖一申请的股数,单位(股)"""
        return self.__bid_volume

    def get_extra_columns(self):
        """获取扩展字段"""
        return self.__extra
